package com.egg.ylt.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.Utils.CustomUtils;
import com.egg.ylt.Utils.StatusBarUtil;
import com.egg.ylt.adapter.ADA_TimeCardRecycler;
import com.egg.ylt.pojo.MemberCardListEntity;
import com.egg.ylt.presenter.impl.TimeCardPresenterImpl;
import com.egg.ylt.view.ITimeCardView;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.utils.AppSharedPreferences;
import com.yonyou.framework.library.common.utils.ListUtil;

import butterknife.BindView;

public class ACT_UserTimeCard extends BaseActivity<TimeCardPresenterImpl> implements ITimeCardView {


    @BindView(R.id.include_iv_back)
    ImageView includeIvBack;
    @BindView(R.id.include_tv_title)
    TextView includeTvTitle;
    @BindView(R.id.include_tv_right)
    TextView includeTvRight;
    @BindView(R.id.include_rl_view)
    RelativeLayout includeRlView;
    @BindView(R.id.recycler_card)
    RecyclerView recyclerCard;
    @BindView(R.id.target_view_ll)
    LinearLayout llTargetView;

    private AppSharedPreferences mSp;
    private String mToken;

    private ADA_TimeCardRecycler recyclerAdapter;

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_user_time_card;
    }

    @Override
    protected View getLoadingTargetView() {
        return llTargetView;
    }

    @Override
    protected void initViewsAndEvents() {

        StatusBarUtil.setStatusBarColor(this, R.color.ylt_whit);
        StatusBarUtil.StatusBarLightMode(this);
        CustomUtils.setImmersiveStatusBar(mContext, includeRlView);

        //初始化view
        initView();

        //初始化recycle
        initRecycler();

    }

    private void initRecycler() {
        // 设置布局管理器
        recyclerCard.setLayoutManager(new LinearLayoutManager(mContext));
        //设置适配器
        recyclerAdapter = new ADA_TimeCardRecycler(mContext);
        recyclerCard.setAdapter(recyclerAdapter);

        //条目的监听
//        recyclerAdapter.setOnItemClickListener(new ADA_TimeCardRecycler.OnItemClickListener() {
//            @Override
//            public void onItemClick(String id) {
//                Intent intent = new Intent();
//                intent.putExtra("id", id);
//                readyGo(ACT_TimeCardDetails.class, intent);
//            }
//        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        //请求次卡列表
        mPresenter.getCardList(Constants.TOKEN, Constants.COMPANYID);
    }

    private void initView() {

        //设置title
        includeTvTitle.setText("我的次卡");
        //返回键的监听
        includeIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        //获取本地token
        mSp = new AppSharedPreferences(mContext);
        mToken = mSp.getString(Constants.USER_TOKEN);

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    public void showBusinessError(ErrorBean error) {

    }

    @Override
    public void getCardList(MemberCardListEntity entity) {
        if (ListUtil.isListEmpty(entity.getList())) {
            toggleShowEmpty(true, R.drawable.empty_no_response, "空空如也~");
            return;
        }

        toggleShowEmpty(false, -1, "");

        // 设置数据
        recyclerAdapter.setList(entity.getList());
    }
}
